HAL WWDG Typical Use Cases for Migration ¶
This section provides information about the HAL WWDG typical use case for migration .
HAL WWDG early wakeup interrupt ¶
The table below outlines the typical scenarios for HAL1 and HAL2 regarding the WWDG peripheral:
In this scenario the user start the wwdg driver and receive a Callbacks (early wakeup Callbacks) that indicates a reset is going to occur, so the user can take the necessary actions before the reset.
|
HAL Version |
Description |
|---|---|
|
HAL1 |
In HAL1, the initialization of the WWDG peripheral was handled by a single init function. This function was responsible for both initializing and configuring its parameters, such as the Prescaler, Window, and Counter. Steps:
|
|
HAL2 |
In HAL2, the initialization process for the WWDG driver was refined by splitting the original init API into two distinct functions: init and start. Steps:
|
Summary ¶
The init function instantiates a handle and associates it with the WWDG instance.
- The start function allows to start the WWDG according to the users parameters:
the prescaler is based on maximum time given by the user in milliseconds ( it can calso be customized to use microseconds or seconds) .
the reload is based on of maximum time given by the user in milliseconds ( it can calso be customized to use microseconds or seconds) .
the window is based on of minimum time given by the user in milliseconds ( it can calso be customized to use microseconds or seconds) .
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
/* Counter and Window register values are already calculated by the user */
#define WWDG_WINDOW 0x50
#define WWDG_COUNTER 0x7F
/* WWDG handle */
WWDG_HandleTypeDef hwwdg;
/* Instance selection */
hwwdg.Instance = WWDG;
/* Set Init */
hwwdg.Init.Prescaler = WWDG_PRESCALER_64;
hwwdg.Init.Window = WWDG_WINDOW;
hwwdg.Init.Counter = WWDG_COUNTER;
hwwdg.Init.EWIMode = WWDG_EWI_DISABLE;
/* Init the WWDG */
HAL_WWDG_Init(&hwwdg)
/* Registering the user callback function */
HAL_WWDG_RegisterCallback(&hwwdg, HAL_WWDG_EWI_CB_ID, User_Callback_function);
/* WWDG refresh : need to be called periodically */
HAL_WWDG_Refresh(&hwwdg);
/* IRQHandler function */
HAL_WWDG_IRQHandler(&hwwdg);
/* WWDG callback function */
HAL_WWDG_EarlyWakeupCallback(&hwwdg, HAL_WWDG_EWI_CB_ID, User_Callback_function);
|
/* Prescaler, reload and window parameters are calculated based on max_time_ms and min_time_ms */
/* max_time_ms */
uint32_t max_time_ms = 780;
/* min_time_ms */
uint32_t min_time_ms = 400;
/* early wakeup status */
uint32_t ewi_status = 0;
/* WWDG handle */
hal_wwdg_handle_t hwwdg;
/* Init the WWDG */
HAL_WWDG_Init(&hwwdg, HAL_WWDG1);
/* Registering the user callback function */
HAL_WWDG_RegisterEarlyWakeupCallback(&hwwdg, User_Callback_function);
/* Config and Start the WWDG: Counter, Prescaler are calculated from the max and min times */
HAL_WWDG_Start(&hwwdg, max_time_ms, min_time_ms, ewi_status);
/* WWDG refresh : need to be called periodically */
HAL_WWDG_Refresh(&hwwdg);
/* IRQHandler function */
HAL_WWDG_IRQHandler(&hwwdg);
/* WWDG EWI callback */
HAL_WWDG_EarlyWakeupCallback(&hwwdg);
|
HAL WWDG max time adjustment ¶
The table below outlines the typical scenarios for HAL1 and HAL2 regarding the WWDG peripheral:
In this scenario user can adjust and modify the maximum time value, according to the current maximum time and the possible value of step.
Maximum time corresponds to “Reset time” given by the user in milliseconds ( it can calso be customized to use microseconds or seconds) .
|
HAL1 Sequence Diagram |
HAL2 Sequence Diagram |
|---|---|
|
|
|
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
/* Counter and Window register values are already calculated by the user */
#define WWDG_WINDOW 0x50
#define WWDG_COUNTER 0x7F
/* WWDG handle */
WWDG_HandleTypeDef hwwdg;
/* Instance selection */
hwwdg.Instance = WWDG;
/* Set Init */
hwwdg.Init.Prescaler = WWDG_PRESCALER_64;
hwwdg.Init.Window = WWDG_WINDOW;
hwwdg.Init.Counter = WWDG_COUNTER;
hwwdg.Init.EWIMode = WWDG_EWI_DISABLE;
/* Init the WWDG */
HAL_WWDG_Init(&hwwdg);
/* WWDG refresh : need to be called periodically */
HAL_WWDG_Refresh(&hwwdg);
/* User recalculate the value of counter manually and set it again */
hwwdg.Init.Counter = 0x6F ;
/* Init the WWDG */
HAL_WWDG_Init(&hwwdg);
/* WWDG refresh : need to be called periodically */
HAL_WWDG_Refresh(&hwwdg);
|
/* Prescaler, reload and window parameters are calculated based on max_time_us and min_time_us */
/* max_time_us */
uint32_t max_time_us = 77000;
/* min_time_us */
uint32_t min_time_us = 40000;
/* early wakeup status */
uint32_t ewi_status = 0;
/* returned_max_time_us */
uint32_t returned_max_time_us = 0;
/* returned_step_us */
uint32_t returned_step_us = 0;
/* WWDG handle */
hal_wwdg_handle_t hwwdg;
/* Init the WWDG */
HAL_WWDG_Init(&hwwdg, HAL_WWDG1);
/* Start the WWDG : prescaler / reload / window and early wakeup are
calculated from the max, min and early wakeup time */
HAL_WWDG_Start(&hwwdg, min_time_us, max_time_us, ewi_status);
/* WWDG refresh : need to be called periodically */
HAL_WWDG_Refresh(&hwwdg);
/* Get max time configured by the WWDG */
returned_max_time_us = HAL_WWDG_GetMaxTime(&hwwdg);
/* Get the WWDG step */
returned_step_us = HAL_WWDG_GetStep_us(&hwwdg);
/* adjust the maximum time according the current time and step */
HAL_WWDG_Start(&hwwdg, min_time_us,( returned_max_time_us + returned_step_us ), ewi_status);
/* WWDG refresh : need to be called periodically */
HAL_WWDG_Refresh(&hwwdg);
|
HAL WWDG min time adjustment ¶
The table below outlines the typical scenarios for HAL1 and HAL2 regarding the WWDG peripheral:
In this scenario user modify the minimum time value,
Minimum time corresponds to “Window time” given by the user in milliseconds ( it can calso be customized to use microseconds or seconds) .
|
HAL1 Sequence Diagram |
HAL2 Sequence Diagram |
|---|---|
|
|
|
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
/* Counter and Window register values are already calculated by the user */
#define WWDG_WINDOW 0x50
#define WWDG_COUNTER 0x7F
/* WWDG handle */
WWDG_HandleTypeDef hwwdg;
/* Instance selection */
hwwdg.Instance = WWDG;
/* Set Init */
hwwdg.Init.Prescaler = WWDG_PRESCALER_64;
hwwdg.Init.Window = WWDG_WINDOW;
hwwdg.Init.Counter = WWDG_COUNTER;
hwwdg.Init.EWIMode = WWDG_EWI_DISABLE;
/* Init the WWDG */
HAL_WWDG_Init(&hwwdg);
/* WWDG refresh */
HAL_WWDG_Refresh(&hwwdg);
/* User recalculate the value of window manually and set it again */
hwwdg.Init.Window = 0x66 ;
/* Init the WWDG */
HAL_WWDG_Init(&hwwdg);
/* WWDG refresh */
HAL_WWDG_Refresh(&hwwdg);
|
/* Prescaler, reload and window parameters are calculated based on max_time_ms and min_time_ms */
/* max_time_ms */
uint32_t max_time_ms = 77;
/* min_time_ms_1 */
uint32_t min_time_ms_1 = 40;
/* min_time_ms_2 */
uint32_t min_time_ms_2 = 30;
/* early wakeup status */
uint32_t ewi_status = 0;
/* WWDG handle */
hal_wwdg_handle_t hwwdg;
/* Init the WWDG */
HAL_WWDG_Init(&hwwdg, HAL_WWDG1);
/* Start the WWDG : prescaler / reload / window and early wakeup are
calculated from the max, min and early wakeup time */
HAL_WWDG_Start(&hwwdg, min_time_ms, max_time_ms, ewi_status);
/* WWDG refresh : need to be called periodically */
HAL_WWDG_Refresh(&hwwdg);
/* Set the knew min_time_ms_2*/
HAL_WWDG_SetMinTime(&hwwdg , min_time_ms_2);
/* WWDG refresh : need to be called periodically */
HAL_WWDG_Refresh(&hwwdg);
|